local falu = fk.CreateSkill{
    name = "ym2__falu",
}
Fk:loadTranslationTable{
    ["ym2__falu"] = "法箓",
    [":ym2__falu"] = "连招技（牌+牌+牌），若这些牌花色：相同，你获得剩余花色牌各一张；各不相同，令一名角色失去或回复1点体力；否则，仅清除第一条记录。你能且仅能于失去手牌时计入此连招。",
    ["@ym2__falu"] = "法箓",
    ["#ym2__falu-choose"] = "法箓：令一名角色失去或回复1点体力",

    ["$ym2__falu1"] = "斗虚盈三清之气而冲牛，撷赤虹凌霄，点紫微之绛唇。",
    ["$ym2__falu2"] = "星守贯太虚之宫而惊鸾，帔兜率婧霞，引银河之流星。",
}
falu:addEffect(fk.AfterCardsMove,{
    anim_type = "drawcard",
    can_trigger = function (self, event, target, player, data)
        if player:hasSkill(falu.name) then
            for _, move in ipairs(data) do
                if move.from == player then
                    return move.extra_data and move.extra_data.combo_skill and move.extra_data.combo_skill[falu.name]
                end
            end
        end
    end,
    on_cost = Util.TrueFunc,
    on_use = function (self, event, target, player, data)
        local room = player.room
        for _, move in ipairs(data) do
            if move.from == player and move.extra_data and move.extra_data.combo_skill and move.extra_data.combo_skill[falu.name] then
                for _, value in ipairs(move.extra_data.combo_skill[falu.name]) do
                    if value ~= "nosuit" then
                        local suits = {"heart", "spade", "diamond", "club"}
                        table.removeOne(suits,value)
                        local cards = {}
                        for _, suit in ipairs(suits) do
                            local card = room:getCardsFromPileByRule(".|.|"..suit)
                            if card then
                                table.insert(cards, card[1])
                            end
                        end
                        if #cards > 0 then
                            room:moveCardTo(cards, Card.PlayerHand, player, fk.ReasonJustMove, falu.name, nil, false, player)
                        end
                    else
                        local success, dat = room:askToUseActiveSkill(player, {
                            skill_name = "ym2__falu_active",
                            prompt = "#ym2__falu-choose",
                            cancelable = false,
                            no_indicate = false,
                        })
                        if success and dat then
                            local to = dat.targets[1]
                            local choice = dat.interaction
                            if choice == "loseHp" then
                                room:loseHp(to, 1, falu.name)
                            else
                                if to:isWounded() then
                                    room:recover{
                                        who = to,
                                        num = 1,
                                        recoverBy = player,
                                        skillName = falu.name,
                                    }
                                end
                            end
                        end
                    end
                end
            end
        end
    end,
})
falu:addEffect(fk.AfterCardsMove,{
    can_refresh = function (self, event, target, player, data)
        if player:hasSkill(falu.name) then
            for _, move in ipairs(data) do
                if move.from == player then
                    for _, info in ipairs(move.moveInfo) do
                        if info.fromArea == Player.Hand then
                            return true
                        end
                    end
                end
            end
        end
    end,
    on_refresh = function (self, event, target, player, data)
        local room = player.room
        for _, move in ipairs(data) do
            if move.from == player then
                for _, info in ipairs(move.moveInfo) do
                    if info.fromArea == Player.Hand then
                        local card = Fk:getCardById(info.cardId)
                        room:addTableMark(player, "@ym2__falu", card:getSuitString(true))
                        local mark = player:getTableMark("@ym2__falu")
                        if #mark == 3 then
                            if mark[1] == mark[2] and mark[2] == mark[3] then
                                move.extra_data = move.extra_data or {}
                                move.extra_data.combo_skill = move.extra_data.combo_skill or {}
                                move.extra_data.combo_skill[falu.name] = move.extra_data.combo_skill[falu.name] or {}
                                p(mark[1])
                                table.insert(move.extra_data.combo_skill[falu.name],string.sub(mark[1],5))
                                mark = 0
                            elseif mark[1] ~= mark[2] and mark[2] ~= mark[3] and mark[1] ~= mark[3] then
                                move.extra_data = move.extra_data or {}
                                move.extra_data.combo_skill = move.extra_data.combo_skill or {}
                                move.extra_data.combo_skill[falu.name] = move.extra_data.combo_skill[falu.name] or {}
                                table.insert(move.extra_data.combo_skill[falu.name],"nosuit")
                                mark = 0
                            else
                                table.remove(mark,1)
                            end
                            room:setPlayerMark(player,"@ym2__falu",mark)
                        end
                    end
                end
            end
        end
    end,
})
return falu